/**
 * Created by udi on 2016/11/26.
 */
'use strict'
let jv = require("libjv").default;


module.exports = {
  init: (app) => {
    const fs = require("fs");
    var path = require('path');

    let mvc = path.normalize(__dirname + "/./routes");

    if (fs.existsSync(mvc) == false) {
      return;
    }


    let files = fs.readdirSync(mvc);

    files.forEach(file => {
      if (!file.endsWith(".js")) return;


      const route = require('./routes/' + file.slice(0, -3))

// routes
      app.use(route.routes(), route.allowedMethods())
    });


    jv.info("自动加载 mvc/ ：" + files.map(it => {
      return it.slice(0, -3);
    }).join(","));
  }
};




